package org.tong.controller;

import org.apache.commons.lang.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tong.service.ServiceThree;

import java.util.Date;

@RestController
public class IndexController {

    private static final Logger log = LoggerFactory.getLogger(IndexController.class);
    @Autowired
    private ServiceThree serviceThree;

    @RequestMapping("/")
    public String index() {
        log.info("visit /");
        //int i = 1 / 0;
        return msg();
    }

    @RequestMapping("/series")
    public String series() {
        log.info("visit /series");
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        String result = serviceThree.index();
        stopWatch.stop();
        System.out.println("耗时：" + stopWatch.getTime());
        return msg() + "->" + result;
    }

    @RequestMapping("/service")
    public String serviceTwo() {
        log.info("visit /service");
        return serviceThree.index();
    }


    private final String msg() {
        return "Welcome to ServiceTwo " + new Date().toString();
    }
}
